﻿using System.Runtime.Serialization;
using Tp.Dto.Allgemein;

namespace Tp.Dto
{
	  public class TitleDto : InPcBase, IAbstractDto
	  {

			#region Members

			private bool isDirty = false;
			private bool hasValue;
			private bool canUndo = false;

			private string name;
			private string nameOld;

			#endregion

			#region Properties

			[DataMember]
			public int TitleDtoId { get; set; }

			[DataMember]
			public string Name
			{
				  get { return this.name; }
				  set
				  {
						if (this.name == value)
						{
							  return;
						}

						if (this.name != value)
						{
							  this.IsDirty = true;
						}
						this.nameOld = this.name;
						this.name = value;
						this.CanUndo = true;
						RaisePropertyChanged(() => Name);
				  }
			}

			public bool HasValue
			{
				  get { return TitleDtoId != null; }
			}

			public bool IsDirty
			{
				  get { return this.isDirty; }
				  set
				  {
						this.isDirty = value;
						RaisePropertyChanged(() => IsDirty);
				  }
			}

			public bool CanUndo
			{
				  get { return this.canUndo; }
				  set
				  {
						this.canUndo = value;
						RaisePropertyChanged(() => CanUndo);
				  }
			}

			#endregion

			#region C-Tor

			public TitleDto(int titleId, string name)
			{
				  this.TitleDtoId = titleId;
				  this.Name = name;
			}

			#endregion

			#region Methods

			public void UndoChanges()
			{
				  this.Name = (this.nameOld == null ? this.Name : this.nameOld);
			}
			
			#endregion

	  }
}
